<?php 
	session_start();
	$var1= $_SESSION["registrado"];
	$var2= $_SESSION["administrador"];
	if ($var1 == null): {
		echo ("User not registered");
	} elseif ($var2 == 0): { 
			echo ("User without permissions");
	} else : {
?>


<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<link href="css/bootstrap.css" rel="stylesheet" media="screen">
<link href="css/bootstrap-responsive.css" rel="stylesheet"	media="screen">

<title>My project manager</title>



</head>

<body>
	<?php include ('configuration.php'); ?>
	<script type="text/javascript"
		src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script src="js/bootstrap.js"></script>


	<div class="navbar navbar-inverse navbar-fixed-top">
		<div class="navbar-inner">
			<div class="container-fluid">
				<button type="button" class="btn btn-navbar" data-toggle="collapse"
					data-target=".nav-collapse">
					<span class="icon-bar"></span> <span class="icon-bar"></span> <span
						class="icon-bar"></span>
				</button>
				<a class="brand" href="http://localhost/bases--grupo10/homeAdmin.php?">My project manager</a>
				<div class="nav-collapse collapse">
					<p class="navbar-text pull-right">
					
						<a href="http://localhost/bases--grupo10/logout.php?" class="navbar-link">Log out</a>
					</p>
					<ul class="nav">
						<li class="active"><a href="http://localhost/bases--grupo10/homeAdmin.php?">Home</a></li>
						<li><a href="http://localhost/bases--grupo10/about.php?">About</a></li>
						<li><a href="http://localhost/bases--grupo10/contact.php?">Contact</a></li>
					</ul>
				</div>
			</div> 
		</div>
	</div>
	
	<?php
		$id_member=$_POST['select_member'];  
		$option=$_POST['select_option'];
		$id_project = $_SESSION["id_proj"]; 
		$no_actualizar=0;
		
		if ($option != 0 && $id_member != 0): {
			//consulto si el proyecto en el que estamos ya tiene responsable
			$q = mysql_query("SELECT id_member_participate FROM participate WHERE id_project_participate = '$id_project' 
								AND is_responsible = 1");
			$result = mysql_fetch_assoc($q);
			$responsible = $result['id_member_participate'];
			
			// check as responsible
			if ($option == 1): {
				// el projecto ya tiene responsable, no se a�aden m�s responsables (s�lo uno por proyecto)
				if ($responsible != null) {
					$no_actualizar=1;
					if ($responsible == $id_member) {
						echo "<h1 style='position:absolute;top:150px;left:50px;font-weight:bold'><font size='5'><u> This member was checked as responsible previously</u></font></h1>";
					} else {
						echo "<h1 style='position:absolute;top:150px;left:50px;font-weight:bold'><font size='5'><u> This project has responsible and only can exist one responsible for project</u></font></h1>";
					}
					echo "<a class='btn btn-primary' type='button' href='http://localhost/bases--grupo10/modifyProject3.php?' style='position:absolute;top:250px;left:50px'>Back</a>";
				} else {
					$q1 = mysql_query("UPDATE participate SET is_responsible=1 WHERE id_member_participate='$id_member'
										AND id_project_participate='$id_project'");
					echo "<h1 class='muted'  style='position:absolute;top:50px;left:50px;'>Member <u>checked as responsible</u> </h1>";
				}
			// uncheck as responsible
			} elseif ($option == 2): {
				if ($responsible != null) {
					if ($responsible != $id_member) {
						$no_actualizar=1;
						echo "<h1 style='position:absolute;top:150px;left:50px;font-weight:bold'><font size='5'><u> This member can't be unchecked as responsible because isn't responsible</u></font></h1>";
						echo "<a class='btn btn-primary' type='button' href='http://localhost/bases--grupo10/modifyProject3.php?' style='position:absolute;top:250px;left:50px'>Back</a>";
	 				} else {
						$q2 = mysql_query("UPDATE participate SET is_responsible=0 WHERE id_member_participate='$id_member' 
										AND id_project_participate='$id_project'");
						echo "<h1 class='muted'  style='position:absolute;top:50px;left:50px;'>Member <u>unchecked as responsible</u> </h1>";
					}
				} else {
					$no_actualizar=1;
					echo "<h1 style='position:absolute;top:150px;left:50px;font-weight:bold'><font size='5'><u> This project hasn't responsible so isn't posible uncheck</u></font></h1>";
					echo "<a class='btn btn-primary' type='button' href='http://localhost/bases--grupo10/modifyProject3.php?' style='position:absolute;top:250px;left:50px'>Back</a>";
				}
			} elseif ($option == 3): {
				//consulto si el miembro seleccionado est� inclu�do en el proyecto 
	    		$q = mysql_query("SELECT id_member_participate FROM participate WHERE id_member_participate = '$id_member' 
	    							AND id_project_participate = '$id_project'");
	    		$result = mysql_result($q, 0);
	    		if ($result != 0) {
	    			$q3 = mysql_query("DELETE FROM participate WHERE id_member_participate = '$id_member' AND id_project_participate = '$id_project'");
	    			echo "<h1 class='muted'  style='position:absolute;top:50px;left:50px;'>Member <u>deleted from the project</u> </h1>";
	    		} else {
	    			$no_actualizar=1;
					echo "<h1 style='position:absolute;top:150px;left:50px;font-weight:bold'><font size='5'><u> Isn't posible delete this member because doen't belong to the project</u></font></h1>";
					echo "<a class='btn btn-primary' type='button' href='http://localhost/bases--grupo10/modifyProject3.php?' style='position:absolute;top:250px;left:50px'>Back</a>";
	    		}		
			}endif;
			
			if ($no_actualizar!=1): {
			?>
				<a class="btn btn-primary" type="button" href="http://localhost/bases--grupo10/modifyProject3.php?" style="position:absolute;top:200px;left:200px">Modified more</a>
				<a class="btn btn-primary" type="button" href="http://localhost/bases--grupo10/homeAdmin.php?" style="position:absolute;top:250px;left:225px">Finish</a>
			<?php }endif;
	
		} else: {
			echo "<h1 style='position:absolute;top:130px;left:50px;font-weight:bold'><font size='5'><u> You must select one member and one option for continue</u></font></h1>"; 
			echo "<a class='btn btn-primary' type='button' href='http://localhost/bases--grupo10/modifyProject3.php?' style='position:absolute;top:250px;left:50px'>Back</a>";	
		}endif;
	?>
	
	
</body>
</html>

<?php }endif;?>